/*
 * Copyright (C) 2018 guomw.Inc. All rights reserved.
 * 项目名称： report-manage
 * 文件名称： DynamicStaticResourceService.java
 * Date：18-11-5 上午10:54
 * Author: guomw
 */

package com.guomw.report.service.service.upload.impl;

import com.guomw.report.common.utils.PropertyUtil;
import com.guomw.report.service.service.ConfigService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author guomw
 * @date 2018/9/30
 */
@Service
@Profile("container")
public class DynamicStaticResourceService extends AbstractStaticResourceService {
    private static final Log log = LogFactory.getLog(DynamicStaticResourceService.class);

    @Autowired
    private ConfigService configService;

    @Autowired
    private void setEnv(Environment env) {
        String uri = configService.getResourcesUri();
        if (uri == null || StringUtils.isEmpty(uri)) {
            throw new IllegalStateException("resourcesUri属性");
        }
        String home = configService.getResourcesHome();
        if (home == null || StringUtils.isEmpty(home)) {
            throw new IllegalStateException("resourcesHome属性");
        }
        try {
            this.uriPrefix = new URI(uri);
            this.fileHome = new URI(home);

        } catch (URISyntaxException e) {
            log.error("解析失败", e);
//            throw new InternalError("解析失败");
        }
    }
}
